package br.fatec.ads.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import br.fatec.ads.dao.AreaDAO;
import br.fatec.ads.exception.AreaException;
import br.fatec.ads.exception.DataBaseException;
import br.fatec.ads.model.Area;

public class AreaExcluir extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public AreaExcluir() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		try {
			HttpSession session = request.getSession(false);
			
			Area area = new Area();
			area.setIdArea(Integer.parseInt(request.getParameter("idAreaExcluir")));
			area.setUsuario(session.getAttribute("usuarioDesc").toString());
			
			AreaDAO areaDAO = new AreaDAO();
		
			areaDAO.excluirArea(area);
			
			request.getRequestDispatcher("AreaPesquisar?acao=SUCESSO_EXCLUIR").forward(request, response);
		} catch (AreaException e) {
			request.getRequestDispatcher("AreaPesquisar?acao=ERRO_EXCLUIR").forward(request, response);
			e.printStackTrace();
		} catch (DataBaseException e) {
			request.getRequestDispatcher("AreaPesquisar?acao=ERRO_EXCLUIR").forward(request, response);
			e.printStackTrace();
		}
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	}

}
